package com.chuangke.flow.plugin.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chuangke.admin.entity.SysUserAuditDept;
import com.chuangke.admin.service.SysUserAuditDeptService;
import com.chuangke.flow.domain.OrderModel;
import com.chuangke.flow.entity.FlowRuNode;
import com.chuangke.flow.entity.FlowRuNodeProcessor;
import com.chuangke.flow.plugin.FlowGetTaskUser;

@Service("defaultFlowGetTaskUser")
public class DefaultFlowGetTaskUser implements FlowGetTaskUser {

	@Autowired
	private SysUserAuditDeptService sysUserAuditDeptService;

	@Override
	public List<String> getTaskUser(FlowRuNode node,FlowRuNodeProcessor nodeProcessor, OrderModel orderModel,String... params) {
		List<SysUserAuditDept> userList = new ArrayList<>();
		List<SysUserAuditDept> list = sysUserAuditDeptService.findUserByRoleDept(nodeProcessor.getProcessId(),
				orderModel.getOrderDeptId());
		if (CollectionUtils.isNotEmpty(list)) {
			userList.addAll(list);
		}
		return userList.stream().map(SysUserAuditDept::getUserId).collect(Collectors.toList());
	}

}
